import dedup from "../../js/dedup"
let init = []
function wishReducer(preVal = init, action) {
    let { type, data } = action
    switch (type) {
        case 'wish':
            return dedup([...preVal, data])
        case 'dewish':
            preVal.forEach((el,index)=>{
                if(data===el.id||data===el.movieId){
                    preVal.splice(index,1)
                }
            })
            return preVal
        case 'clearWish':
            return preVal=data
        default:
            return preVal
    }
}

export default wishReducer